var map;
var markers = {};

var mapCenter = new google.maps.LatLng( 34.724031, -86.499696 );
var mapZoom = 11;

function onMapClick( event )
{
	window.external.OnMapClick( event.latLng.lat(), event.latLng.lng() );
}

function initializeMap()
{
	var mapOptions = { zoom: mapZoom, center: mapCenter, mapTypeId: google.maps.MapTypeId.ROADMAP };
	map = new google.maps.Map( document.getElementById( "map_canvas" ), mapOptions );
	google.maps.event.addListener( map, "click", onMapClick );
}

function updateMarker( label, latitude, longitude, icon )
{
	removeMarker( label );
	var position = new google.maps.LatLng( latitude, longitude );
	var marker = new google.maps.Marker( { position: position, map: map, title: label, icon: icon } );
	var onMarkerClick = "window.external.OnMarkerClick('" + label + "');";
	google.maps.event.addListener( marker, "click", new Function( onMarkerClick ) );
	markers[ label ] = marker;
}

function updateTempMarker( latitude, longitude )
{
	removeMarker( "tempMarker" );
	var position = new google.maps.LatLng( latitude, longitude );
	var marker = new google.maps.Marker( { position: position, map: map, title: "Selected Location" } );
	markers.tempMarker = marker;
}

function panToMarker( label )
{
	if ( markers.hasOwnProperty( label ) )
	{
		var marker = markers[ label ];
		map.panTo( marker.position );
	}
}

function removeMarker( label )
{
	if ( markers.hasOwnProperty( label ) )
	{
		var marker = markers[ label ];
		marker.setMap( null );
		delete markers[ label ];
	}
}
